import React from 'react';
import {BrowserRouter, Switch} from "react-router-dom";
import Orders from '../../component/page/orders/Orders';
import Main from '../page/Main';
import { withReducersIntl } from '../store/StoreUtil';
import { setIntl } from '../util/AppUtil';
import Login from '../page/login/Login';
import ReduxRouter from './ReduxRouter';
import LoginReducer from '../store/reducer/LoginReducer';
import UseTest from '../../component/page/hooks/UseTest';
import UseDemo from '../../component/page/orders/UseDemo';

/**
 * 顶层的Router
 */

class AppRouter extends React.Component{
    constructor(props) {
        super(props);
        this.state = {}
        setIntl(this.props.intl);
    }

    //  减少因为Props改变而导致页面的渲染次数
    // shouldComponentUpdate(nextProps, nextState){
        // if (nextProps.security !== this.props.security) {
        //     return true
        // }
        // if (nextProps.drawer.placement !== this.props.drawer.placement) {
        //     return true
        // }
        // if(nextProps.drawer.list.length !== this.props.drawer.list.length ){
        //     if( nextProps.drawer.list.length === 0 || (nextProps.drawer.list.length === 1 && this.props.drawer.list.length === 0)) {
        //         return true
        //     }
        // }
    // }

    componentDidMount() {
        // LoginReducer.actions.setValue({userInfo: '11'})
    }

    render() {
        const { userInfo } = this.props;
        return (
            <BrowserRouter>
                {
                    !userInfo ?
                    <ReduxRouter path='/' component={Login} />
                    :
                    //已登录
                    <Switch>
                        <ReduxRouter path='/main' component={Main} />
                        <ReduxRouter path='/h' component={UseTest} />
                        <ReduxRouter path='/u' component={UseDemo} />
                        <ReduxRouter path='/' component={Orders} />
                    </Switch>
                }
            </BrowserRouter>
        );
    }
}

export default withReducersIntl(AppRouter, LoginReducer)